/*
 * VectorCase.cpp
 *
 *  Created on: 2012-9-7
 *      Author: yangentao@gmail.com
 */
#include "test.h"
#include "../src/yet/Vector.h"
using namespace  yet;
TEST(Vector, constructor1) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	EXPECT_TRUE(v.equals(arr, 3));
}

TEST(Vector, constructor2) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(3);
	EXPECT_GE(v.getCapcity(), 3);
}
TEST(Vector, constructor3) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	Vector<int> v2(v);

	EXPECT_TRUE(v2.equals(arr, 3));
}
TEST(Vector, operatorEQ) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	Vector<int> v2;
	v2 = v;
	EXPECT_TRUE(v2.equals(arr, 3));
}
TEST(Vector, copyFrom1) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	Vector<int> v2;
	v2.copyFrom(arr, 3);
	EXPECT_TRUE(v2.equals(arr, 3));
}
TEST(Vector, copyFrom2) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v2;
	v2.copyFrom(arr, 3);
	EXPECT_TRUE(v2.equals(arr, 3));
}
TEST(Vector, length) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v2;
	v2.copyFrom(arr, 3);
	EXPECT_EQ(v2.length(), 3);
}

TEST(Vector, clear) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v2;
	v2.copyFrom(arr, 3);
	v2.clear();
	EXPECT_EQ(v2.length(), 0);
}
TEST(Vector, ensureCapcity) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v2(arr, 3);
	v2.ensureCapcity(16);
	EXPECT_GE(v2.getCapcity(), 16);
	EXPECT_EQ(v2.length(), 3);
}
TEST(Vector, get) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v2(arr, 3);
	EXPECT_EQ(v2[0], 1);
	EXPECT_EQ(v2[1], 2);
	EXPECT_EQ(v2[2], 3);
	EXPECT_EQ(v2.length(), 3);
}

TEST(Vector, getRef) {
	Vector<int> v2;
	v2.getRef(0) = 1;
	v2[1] = 2;
	v2.getRef(2) = 3;
	EXPECT_EQ(v2[0], 1);
	EXPECT_EQ(v2[1], 2);
	EXPECT_EQ(v2[2], 3);
	EXPECT_EQ(v2.length(), 3);
}

TEST(Vector, first) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v2(arr, 3);
	EXPECT_EQ(v2.first(), 1);
	EXPECT_EQ(v2.length(), 3);
}
TEST(Vector, last) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v2(arr, 3);
	EXPECT_EQ(v2.last(), 3);
	EXPECT_EQ(v2.length(), 3);
}

TEST(Vector, set) {
	Vector<int> v2;
	v2.set(0, 9);
	v2.set(1, 2);
	v2.set(2, 3);
	v2.set(0, 1);
	EXPECT_EQ(v2[0], 1);
	EXPECT_EQ(v2[1], 2);
	EXPECT_EQ(v2[2], 3);
	EXPECT_EQ(v2.length(), 3);
}

TEST(Vector, contains) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v2(arr, 3);
	EXPECT_TRUE(v2.contains(1));
	EXPECT_TRUE(v2.contains(2));
	EXPECT_TRUE(v2.contains(3));
	EXPECT_EQ(v2.length(), 3);
}
TEST(Vector, getRange1) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	Vector<int> v2;
	v.getRange(v2, 0, 3);
	EXPECT_EQ(v2[0], 1);
	EXPECT_EQ(v2[1], 2);
	EXPECT_EQ(v2[2], 3);
	EXPECT_EQ(v2.length(), 3);
}
TEST(Vector, getRange2) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	Vector<int> v2;
	v.getRange(v2, 0, 1);
	EXPECT_EQ(v2[0], 1);
	EXPECT_EQ(v2.length(), 1);
}

TEST(Vector, getRange3) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	Vector<int> v2;
	v.getRange(v2, 2, 1);
	EXPECT_EQ(v2[0], 3);
	EXPECT_EQ(v2.length(), 1);
}
TEST(Vector, getRange4) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	Vector<int> v2;
	v.getRange(v2, 1, 1);
	EXPECT_EQ(v2[0], 2);
	EXPECT_EQ(v2.length(), 1);

}

TEST(Vector, append1) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v;
	v.append(1);
	v.append(2);
	v.append(3);
	EXPECT_TRUE(v.equals(arr, 3));
}

TEST(Vector, append2) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v;
	v.append(arr, 3);
	EXPECT_TRUE(v.equals(arr, 3));
}
TEST(Vector, append3) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 2);
	v.append(3);
	EXPECT_TRUE(v.equals(arr, 3));
}

TEST(Vector, insert1) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v;
	v.insert(0, 1);
	v.insert(1, 3);
	v.insert(1, 2);
	EXPECT_TRUE(v.equals(arr, 3));
}

TEST(Vector, remove1) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	v.insert(0, 1); //1123
	v.insert(1, 3); //13123
	v.insert(1, 2); //123123
	v.append(4); //1231234
	v.remove(0); //231234
	int vals[] = { 2, 3, 1, 2, 3, 4 };
	EXPECT_TRUE(v.equals(vals, 6));
}

TEST(Vector, remove2) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	v.insert(0, 1);
	v.insert(1, 3);
	v.insert(1, 2);
	v.append(4); //1231234
	v.remove(0); //231234
	v.remove(1); //21234
	v.remove(1); //2234
	v.remove(3); //223
	int vals[] = { 2, 2, 3 };
	EXPECT_TRUE(v.equals(vals, 3));
}

TEST(Vector, replace1) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	v.remove(0); //23
	v.append(5); //235
	v.insert(2, 4); //2345
	v.insert(4, 6); //23456
	int ar[] = { 2, 3, 4, 5, 6 };
	EXPECT_TRUE(v.equals(ar, 5));
	EXPECT_EQ(v.length(), 5);

}

TEST(Vector, replace2) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	int ar[] = { 1, 2, 1, 2 };
	v.replace(0, 2, ar, 4);
	int ar2[] = { 1, 2, 1, 2, 3 };
	EXPECT_TRUE(v.equals(ar2, 5));
	EXPECT_EQ(v.length(), 5);

}

TEST(Vector, replace3) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	int ar[] = { 1, 2, 1, 2 };
	v.replace(2, 1, ar, 4);
	int ar2[] = { 1, 2, 1, 2, 1, 2 };
	EXPECT_TRUE(v.equals(ar2, 6));
	EXPECT_EQ(v.length(), 6);

}

TEST(Vector, replace4) {
	int arr[] = { 1, 1000 };
	Vector<int> v(arr, 2);

	int ar[] = { 2, 3, 4 };
//	v.dump();
	v.replace(1, 0, ar, 3);
//	v.dump();

}

TEST(Vector, removeValue1) {
	int arr[] = { 1, 2, 3 };
	Vector<int> v(arr, 3);
	v.removeValue(2);
	int ar2[] = { 1, 3};
	EXPECT_TRUE(v.equals(ar2, 2));
	EXPECT_EQ(v.length(), 2);

}
TEST(Vector, removeAllValues1) {
	int arr[] = { 1, 2, 3, 2 };
	Vector<int> v(arr, 4);
	v.removeAllValues(2);
	int ar2[] = { 1, 3};
	EXPECT_TRUE(v.equals(ar2, 2));
	EXPECT_EQ(v.length(), 2);

}
